From 92781707366ec66f39ea7ef87ba5a0890ed97a4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 15 Aug 2005 19:00:29 +0000 Subject: [PATCH] readded babl/babl-base in babl/base --- ChangeLog | 29 +++ babl/base/.cvsignore | 6 + babl/base/Makefile.am | 24 ++ babl/base/babl-base.c | 74 ++++++ babl/base/babl-base.h | 26 ++ babl/base/conversions-type.c | 24 ++ babl/base/model-gray.c | 468 +++++++++++++++++++++++++++++++++++ babl/base/model-grayscale.c | 468 +++++++++++++++++++++++++++++++++++ babl/base/model-rgb.c | 439 ++++++++++++++++++++++++++++++++ babl/base/models.c | 21 ++ babl/base/pixel-formats.c | 49 ++++ babl/base/rgb-constants.h | 22 ++ babl/base/type-double.c | 49 ++++ babl/base/type-float.c | 75 ++++++ babl/base/type-u16.c | 84 +++++++ babl/base/type-u8.c | 85 +++++++ babl/base/types.c | 24 ++ babl/base/util.h | 46 ++++ configure.ac | 2 +- 19 files changed, 2014 insertions(+), 1 deletion(-) create mode 100644 babl/base/.cvsignore create mode 100644 babl/base/Makefile.am create mode 100644 babl/base/babl-base.c create mode 100644 babl/base/babl-base.h create mode 100644 babl/base/conversions-type.c create mode 100644 babl/base/model-gray.c create mode 100644 babl/base/model-grayscale.c create mode 100644 babl/base/model-rgb.c create mode 100644 babl/base/models.c create mode 100644 babl/base/pixel-formats.c create mode 100644 babl/base/rgb-constants.h create mode 100644 babl/base/type-double.c create mode 100644 babl/base/type-float.c create mode 100644 babl/base/type-u16.c create mode 100644 babl/base/type-u8.c create mode 100644 babl/base/types.c create mode 100644 babl/base/util.h diff --git a/ChangeLog b/ChangeLog index bde9a00..b74868b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2005-08-15 Øyvind Kolås + + * configure.ac: add rule to generate babl/base/Makefile + * babl/base: new directory + * babl/base/Makefile.am + * babl/base/babl-base.[ch] + * babl/base/type-double.c + * babl/base/type-float.c + * babl/base/type-u8.c + * babl/base/type-u16.c + * babl/base/model-rgb.c + * babl/base/model-grayscale.c + * babl/base/.cvsignore: added code removed in previous commit, in + a more oragnised manner. + + +2005-08-15 Øyvind Kolås + + * babl/babl-base/babl-base.[ch] + * babl/babl-base/babl-base-components.c + * babl/babl-base/babl-base-conversions.c + * babl/babl-base/babl-base-conversions-model.c + * babl/babl-base/babl-base-conversions-type.c + * babl/babl-base/babl-base-models.c + * babl/babl-base/babl-base-pixel-formats.c + * babl/babl-base/babl-base-types.c + * babl/babl-base/Makefile.am + * babl/babl-base/: removed + 2005-08-15 Øyvind Kolås * babl/babl-classes.h: BablPixelFormat: changed order of attributes to diff --git a/babl/base/.cvsignore b/babl/base/.cvsignore new file mode 100644 index 0000000..ac46a4b --- /dev/null +++ b/babl/base/.cvsignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +.deps +*.lo +*.la +.libs diff --git a/babl/base/Makefile.am b/babl/base/Makefile.am new file mode 100644 index 0000000..c31d8a5 --- /dev/null +++ b/babl/base/Makefile.am @@ -0,0 +1,24 @@ +h_sources = \ + babl-base.h + +c_sources = \ + babl-base.c \ + type-double.c \ + type-float.c \ + type-u8.c \ + type-u16.c \ + model-rgb.c \ + model-grayscale.c + +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/babl + +noinst_LTLIBRARIES= libbase.la +libbase_la_SOURCES= $(h_sources) $(c_sources) + +EXTRA_DIST := \ + .cvsignore \ + rgb-constants.h \ + util.h + + +LDADD = -lm diff --git a/babl/base/babl-base.c b/babl/base/babl-base.c new file mode 100644 index 0000000..8d4ea7e --- /dev/null +++ b/babl/base/babl-base.c @@ -0,0 +1,74 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +extern int babl_hmpf_on_name_lookups; + +static void types (void); +static void models (void); + +void +babl_base_init (void) +{ + babl_hmpf_on_name_lookups ++; + + types (); + models (); + + babl_hmpf_on_name_lookups --; +} + +void +babl_base_destroy (void) +{ + /* done by the destruction of the elemental babl clases */ +} + +/* + * types + */ + +void babl_base_type_double (void); +void babl_base_type_float (void); +void babl_base_type_u8 (void); +void babl_base_type_u16 (void); + +static void +types (void) +{ + babl_base_type_double (); /* must be registered first since it is the + reference */ + babl_base_type_float (); + babl_base_type_u8 (); + babl_base_type_u16 (); +} + +/* + * models + */ + +void babl_base_model_rgb (void); +void babl_base_model_grayscale (void); + +static void +models (void) +{ + babl_base_model_rgb (); /* must be registered first since it is the + reference */ + babl_base_model_grayscale (); +} diff --git a/babl/base/babl-base.h b/babl/base/babl-base.h new file mode 100644 index 0000000..1c01346 --- /dev/null +++ b/babl/base/babl-base.h @@ -0,0 +1,26 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _BABL_BASE_H +#define _BABL_BASE_H + +void babl_base_init (); +void babl_base_destroy (); + +#endif diff --git a/babl/base/conversions-type.c b/babl/base/conversions-type.c new file mode 100644 index 0000000..cc738fc --- /dev/null +++ b/babl/base/conversions-type.c @@ -0,0 +1,24 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include "babl.h" +#include + + diff --git a/babl/base/model-gray.c b/babl/base/model-gray.c new file mode 100644 index 0000000..20d31eb --- /dev/null +++ b/babl/base/model-gray.c @@ -0,0 +1,468 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl.h" +#include "util.h" +#include "rgb-constants.h" +#include "math.h" + +static void components (void); +static void models (void); +static void conversions (void); + +void babl_base_model_grayscale (void) +{ + components (); + models (); + conversions (); +} + +static void +components (void) +{ + babl_component_new ( + "luminance", + "id", BABL_LUMINANCE, + "luma", + NULL); +} + +static void +models (void) +{ + babl_model_new ( + "grayscale", + "id", BABL_GRAYSCALE, + babl_component_id (BABL_LUMINANCE), + NULL); + + babl_model_new ( + "grayscale-gamma2.2", + "id", BABL_GRAYSCALE_GAMMA_2_2, + babl_component_id (BABL_LUMINANCE), + NULL); + + babl_model_new ( + "grayscale-alpha", + "id", BABL_GRAYSCALE_ALPHA, + babl_component_id (BABL_LUMINANCE), + babl_component_id (BABL_ALPHA), + NULL); + + babl_model_new ( + "grayscale-alpha-premultiplied", + "id", BABL_GRAYSCALE_ALPHA_PREMULTIPLIED, + babl_component_id (BABL_LUMINANCE_MUL_ALPHA), + babl_component_id (BABL_ALPHA), + NULL); + +} + + +static void +rgb_to_grayscale (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double red, green, blue; + double luminance, alpha; + + red = *(double *)src[0]; + green = *(double *)src[1]; + blue = *(double *)src[2]; + if (src_bands>3) + alpha = *(double *)src[3]; + else + alpha = 1.0; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + *(double*)dst[0] = luminance; + + if (dst_bands==2) + *(double*)dst[1] = alpha; + + BABL_PLANAR_STEP + } +} + + +static void +rgb_to_grayscale_2_2 (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double red, green, blue; + double luminance, alpha; + + red = *(double *) src[0]; + green = *(double *) src[1]; + blue = *(double *) src[2]; + if (src_bands>3) + alpha = *(double *)src[3]; + else + alpha = 1.0; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + *(double*)dst[0] = pow (luminance, 2.2); + + if (dst_bands==2) + *(double*)dst[1] = alpha; + + BABL_PLANAR_STEP + } +} + + +static void +grayscale_2_2_to_rgb (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double luminance; + double red, green, blue; + double alpha; + + luminance = pow (*(double *)src[0], (1.0F/2.2F)); + red = luminance; + green = luminance; + blue = luminance; + if (src_bands > 1) + alpha = *(double *)src[1]; + else + alpha = 1.0; + + *(double*)dst[0] = red; + *(double*)dst[1] = green; + *(double*)dst[2] = blue; + + if (dst_bands>3) + *(double*)dst[3] = alpha; + + BABL_PLANAR_STEP + } +} + + + +static void +grayscale_to_rgb (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double luminance; + double red, green, blue; + double alpha; + + luminance = *(double *)src[0]; + red = luminance; + green = luminance; + blue = luminance; + if (src_bands > 1) + alpha = *(double *)src[1]; + else + alpha = 1.0; + + *(double*)dst[0] = red; + *(double*)dst[1] = green; + *(double*)dst[2] = blue; + + if (dst_bands>3) + *(double*)dst[3] = alpha; + + BABL_PLANAR_STEP + } +} + +static void +grayscale_alpha_premultiplied_to_rgba (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + assert (src_bands == 2); + assert (dst_bands == 4); + + while (n--) + { + double luminance = *(double *)src[0]; + double alpha = *(double *)src[1]; + + if (alpha > 0.001) + { + luminance = luminance / alpha; + } + else + { + luminance = 0.0; + } + + *(double*)dst[0] = luminance; + *(double*)dst[1] = luminance; + *(double*)dst[2] = luminance; + *(double*)dst[3] = alpha; + BABL_PLANAR_STEP + } +} + + +static void +rgba_to_grayscale_alpha_premultiplied (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY; + assert (src_bands == 4); + assert (dst_bands == 2); + + while (n--) + { + double red = *(double *)src[0]; + double green = *(double *)src[1]; + double blue = *(double *)src[2]; + double alpha = *(double *)src[3]; + double luminance; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + + luminance *= alpha; + + *(double*)dst[0] = luminance; + *(double*)dst[2] = alpha; + BABL_PLANAR_STEP + } +} + +static void +non_premultiplied_to_premultiplied (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + + while (n--) + { + double alpha; + int band; + + alpha = *(double *)src[src_bands-1]; + for (band=0; band0.001) + { + *(double*)dst[band] = *(double*) src[band] / alpha; + } + else + { + *(double*)dst[band] = 0.001; + } + } + *(double*)dst[dst_bands-1] = alpha; + + BABL_PLANAR_STEP + } +} + +static void +conversions (void) +{ + babl_conversion_new ( + "babl-base: grayscale-gamma2.2 to rgba", + "source", babl_model_id (BABL_GRAYSCALE_GAMMA_2_2), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_2_2_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-gamma2.2", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_GAMMA_2_2), + "planar", rgb_to_grayscale_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale to rgba", + "source", babl_model_id (BABL_GRAYSCALE), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale to rgb", + "source", babl_model_id (BABL_GRAYSCALE), + "destination", babl_model_id (BABL_RGB), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to rgba", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to rgb", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_RGB), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-alpha", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb to grayscale-alpha", + "source", babl_model_id (BABL_RGB), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb to grayscale", + "source", babl_model_id (BABL_RGB), + "destination", babl_model_id (BABL_GRAYSCALE), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to grayscale-alpha-premultiplied", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "planar", non_premultiplied_to_premultiplied, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha-premultuplied to grayscale-alpha", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", premultiplied_to_non_premultiplied, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha-premultiplied to rgba", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_alpha_premultiplied_to_rgba, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-alpha-premultiplied", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "planar", rgba_to_grayscale_alpha_premultiplied, + NULL + ); +} diff --git a/babl/base/model-grayscale.c b/babl/base/model-grayscale.c new file mode 100644 index 0000000..20d31eb --- /dev/null +++ b/babl/base/model-grayscale.c @@ -0,0 +1,468 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl.h" +#include "util.h" +#include "rgb-constants.h" +#include "math.h" + +static void components (void); +static void models (void); +static void conversions (void); + +void babl_base_model_grayscale (void) +{ + components (); + models (); + conversions (); +} + +static void +components (void) +{ + babl_component_new ( + "luminance", + "id", BABL_LUMINANCE, + "luma", + NULL); +} + +static void +models (void) +{ + babl_model_new ( + "grayscale", + "id", BABL_GRAYSCALE, + babl_component_id (BABL_LUMINANCE), + NULL); + + babl_model_new ( + "grayscale-gamma2.2", + "id", BABL_GRAYSCALE_GAMMA_2_2, + babl_component_id (BABL_LUMINANCE), + NULL); + + babl_model_new ( + "grayscale-alpha", + "id", BABL_GRAYSCALE_ALPHA, + babl_component_id (BABL_LUMINANCE), + babl_component_id (BABL_ALPHA), + NULL); + + babl_model_new ( + "grayscale-alpha-premultiplied", + "id", BABL_GRAYSCALE_ALPHA_PREMULTIPLIED, + babl_component_id (BABL_LUMINANCE_MUL_ALPHA), + babl_component_id (BABL_ALPHA), + NULL); + +} + + +static void +rgb_to_grayscale (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double red, green, blue; + double luminance, alpha; + + red = *(double *)src[0]; + green = *(double *)src[1]; + blue = *(double *)src[2]; + if (src_bands>3) + alpha = *(double *)src[3]; + else + alpha = 1.0; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + *(double*)dst[0] = luminance; + + if (dst_bands==2) + *(double*)dst[1] = alpha; + + BABL_PLANAR_STEP + } +} + + +static void +rgb_to_grayscale_2_2 (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double red, green, blue; + double luminance, alpha; + + red = *(double *) src[0]; + green = *(double *) src[1]; + blue = *(double *) src[2]; + if (src_bands>3) + alpha = *(double *)src[3]; + else + alpha = 1.0; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + *(double*)dst[0] = pow (luminance, 2.2); + + if (dst_bands==2) + *(double*)dst[1] = alpha; + + BABL_PLANAR_STEP + } +} + + +static void +grayscale_2_2_to_rgb (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double luminance; + double red, green, blue; + double alpha; + + luminance = pow (*(double *)src[0], (1.0F/2.2F)); + red = luminance; + green = luminance; + blue = luminance; + if (src_bands > 1) + alpha = *(double *)src[1]; + else + alpha = 1.0; + + *(double*)dst[0] = red; + *(double*)dst[1] = green; + *(double*)dst[2] = blue; + + if (dst_bands>3) + *(double*)dst[3] = alpha; + + BABL_PLANAR_STEP + } +} + + + +static void +grayscale_to_rgb (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + double luminance; + double red, green, blue; + double alpha; + + luminance = *(double *)src[0]; + red = luminance; + green = luminance; + blue = luminance; + if (src_bands > 1) + alpha = *(double *)src[1]; + else + alpha = 1.0; + + *(double*)dst[0] = red; + *(double*)dst[1] = green; + *(double*)dst[2] = blue; + + if (dst_bands>3) + *(double*)dst[3] = alpha; + + BABL_PLANAR_STEP + } +} + +static void +grayscale_alpha_premultiplied_to_rgba (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + assert (src_bands == 2); + assert (dst_bands == 4); + + while (n--) + { + double luminance = *(double *)src[0]; + double alpha = *(double *)src[1]; + + if (alpha > 0.001) + { + luminance = luminance / alpha; + } + else + { + luminance = 0.0; + } + + *(double*)dst[0] = luminance; + *(double*)dst[1] = luminance; + *(double*)dst[2] = luminance; + *(double*)dst[3] = alpha; + BABL_PLANAR_STEP + } +} + + +static void +rgba_to_grayscale_alpha_premultiplied (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY; + assert (src_bands == 4); + assert (dst_bands == 2); + + while (n--) + { + double red = *(double *)src[0]; + double green = *(double *)src[1]; + double blue = *(double *)src[2]; + double alpha = *(double *)src[3]; + double luminance; + + luminance = red * RGB_LUMINANCE_RED + + green * RGB_LUMINANCE_GREEN + + blue * RGB_LUMINANCE_BLUE; + + luminance *= alpha; + + *(double*)dst[0] = luminance; + *(double*)dst[2] = alpha; + BABL_PLANAR_STEP + } +} + +static void +non_premultiplied_to_premultiplied (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + + while (n--) + { + double alpha; + int band; + + alpha = *(double *)src[src_bands-1]; + for (band=0; band0.001) + { + *(double*)dst[band] = *(double*) src[band] / alpha; + } + else + { + *(double*)dst[band] = 0.001; + } + } + *(double*)dst[dst_bands-1] = alpha; + + BABL_PLANAR_STEP + } +} + +static void +conversions (void) +{ + babl_conversion_new ( + "babl-base: grayscale-gamma2.2 to rgba", + "source", babl_model_id (BABL_GRAYSCALE_GAMMA_2_2), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_2_2_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-gamma2.2", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_GAMMA_2_2), + "planar", rgb_to_grayscale_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale to rgba", + "source", babl_model_id (BABL_GRAYSCALE), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale to rgb", + "source", babl_model_id (BABL_GRAYSCALE), + "destination", babl_model_id (BABL_RGB), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to rgba", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to rgb", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_RGB), + "planar", grayscale_to_rgb, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-alpha", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb to grayscale-alpha", + "source", babl_model_id (BABL_RGB), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb to grayscale", + "source", babl_model_id (BABL_RGB), + "destination", babl_model_id (BABL_GRAYSCALE), + "planar", rgb_to_grayscale, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha to grayscale-alpha-premultiplied", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "planar", non_premultiplied_to_premultiplied, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha-premultuplied to grayscale-alpha", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA), + "planar", premultiplied_to_non_premultiplied, + NULL + ); + + babl_conversion_new ( + "babl-base: grayscale-alpha-premultiplied to rgba", + "source", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "destination", babl_model_id (BABL_RGBA), + "planar", grayscale_alpha_premultiplied_to_rgba, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to grayscale-alpha-premultiplied", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_GRAYSCALE_ALPHA_PREMULTIPLIED), + "planar", rgba_to_grayscale_alpha_premultiplied, + NULL + ); +} diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c new file mode 100644 index 0000000..c143558 --- /dev/null +++ b/babl/base/model-rgb.c @@ -0,0 +1,439 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include "babl.h" +#include "util.h" + +static void models (void); +static void components (void); +static void conversions (void); +static void pixel_formats (void); + +void +babl_base_model_rgb (void) +{ + components (); + models (); + conversions (); + pixel_formats (); +} + +static void +components (void) +{ + babl_component_new ( + "red", + "id", BABL_RED, + "luma", + "chroma", + NULL); + + babl_component_new ( + "green", + "id", BABL_GREEN, + "luma", + "chroma", + NULL); + + babl_component_new ( + "blue", + "id", BABL_BLUE, + "luma", + "chroma", + NULL); + + babl_component_new ( + "red-gamma2.2", + "id", BABL_RED_GAMMA_2_2, + "luma", + "chroma", + NULL); + + babl_component_new ( + "green-gamma2.2", + "id", BABL_GREEN_GAMMA_2_2, + "luma", + "chroma", + NULL); + + babl_component_new ( + "blue-gamma2.2", + "id", BABL_BLUE_GAMMA_2_2, + "luma", + "chroma", + NULL); + + + babl_component_new ( + "alpha", + "id", BABL_ALPHA, + "alpha", + NULL); + + babl_component_new ( + "red*alpha", + "id", BABL_RED_MUL_ALPHA, + "luma", + "chroma", + "alpha", + NULL); + babl_component_new ( + "green*alpha", + "id", BABL_GREEN_MUL_ALPHA, + "luma", + "chroma", + "alpha", + NULL); + babl_component_new ( + "blue*alpha", + "id", BABL_BLUE_MUL_ALPHA, + "luma", + "chroma", + "alpha", + NULL); + + babl_component_new ( + "luminance*alpha", + "id", BABL_LUMINANCE_MUL_ALPHA, + "luma", + NULL); +} + +static void +models (void) +{ + babl_model_new ( + "rgba", + "id", BABL_RGBA, + babl_component_id (BABL_RED), + babl_component_id (BABL_GREEN), + babl_component_id (BABL_BLUE), + babl_component_id (BABL_ALPHA), + NULL); + + babl_model_new ( + "rgb", + "id", BABL_RGB, + babl_component_id (BABL_RED), + babl_component_id (BABL_GREEN), + babl_component_id (BABL_BLUE), + NULL); + + babl_model_new ( + "rgbA", + "id", BABL_RGBA_PREMULTIPLIED, + babl_component_id (BABL_RED_MUL_ALPHA), + babl_component_id (BABL_GREEN_MUL_ALPHA), + babl_component_id (BABL_BLUE_MUL_ALPHA), + babl_component_id (BABL_ALPHA), + NULL); + + babl_model_new ( + "rgb-gamma2.2", + "id", BABL_RGB_GAMMA_2_2, + babl_component_id (BABL_RED_GAMMA_2_2), + babl_component_id (BABL_GREEN_GAMMA_2_2), + babl_component_id (BABL_BLUE_GAMMA_2_2), + NULL); + + babl_model_new ( + "rgba-gamma2.2", + "id", BABL_RGBA_GAMMA_2_2, + babl_component_id (BABL_RED_GAMMA_2_2), + babl_component_id (BABL_GREEN_GAMMA_2_2), + babl_component_id (BABL_BLUE_GAMMA_2_2), + babl_component_id (BABL_ALPHA), + NULL); +} + +static void +copy_strip_1 (int src_bands, + void **src, + int *src_pitch, + int dst_bands, + void **dst, + int *dst_pitch, + int n) +{ + BABL_PLANAR_SANITY + while (n--) + { + int i; + + for (i=0;i0.001) + { + *(double*)dst[band] = *(double*) src[band] / alpha; + } + else + { + *(double*)dst[band] = 0.001; + } + } + *(double*)dst[dst_bands-1] = alpha; + + BABL_PLANAR_STEP + } +} + + + + +static void +conversions (void) +{ + babl_conversion_new ( + "babl-base: rgba to rgba", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_RGBA), + "planar", copy_strip_1, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to rgb-gamma2.2", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_RGB_GAMMA_2_2), + "planar", g3_gamma_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to rgba-gamma2.2", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_RGBA_GAMMA_2_2), + "planar", g3_gamma_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb-gamma2.2 to rgba", + "source", babl_model_id (BABL_RGB_GAMMA_2_2), + "destination", babl_model_id (BABL_RGBA), + "planar", g3_inv_gamma_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba-gamma2.2 to rgba", + "source", babl_model_id (BABL_RGBA_GAMMA_2_2), + "destination", babl_model_id (BABL_RGBA), + "planar", g3_inv_gamma_2_2, + NULL + ); + + babl_conversion_new ( + "babl-base: rgb to rgba", + "source", babl_model_id (BABL_RGB), + "destination", babl_model_id (BABL_RGBA), + "planar", copy_strip_1, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to rgb", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_RGB), + "planar", copy_strip_1, + NULL + ); + + babl_conversion_new ( + "babl-base: rgba to rgbA", + "source", babl_model_id (BABL_RGBA), + "destination", babl_model_id (BABL_RGBA_PREMULTIPLIED), + "planar", non_premultiplied_to_premultiplied, + NULL + ); + + babl_conversion_new ( + "babl-base: rgbA to rgba", + "source", babl_model_id (BABL_RGBA_PREMULTIPLIED), + "destination", babl_model_id (BABL_RGBA), + "planar", premultiplied_to_non_premultiplied, + NULL + ); +} + +static void +pixel_formats (void) +{ + babl_pixel_format_new ( + "srgb", + "id", BABL_SRGB, + babl_model_id (BABL_RGB_GAMMA_2_2), + babl_type_id (BABL_U8), + babl_component_id (BABL_RED_GAMMA_2_2), + babl_component_id (BABL_GREEN_GAMMA_2_2), + babl_component_id (BABL_BLUE_GAMMA_2_2), + NULL); + + babl_pixel_format_new ( + "srgba", + "id", BABL_SRGBA, + babl_model_id (BABL_RGBA_GAMMA_2_2), + babl_type_id (BABL_U8), + babl_component_id (BABL_RED_GAMMA_2_2), + babl_component_id (BABL_GREEN_GAMMA_2_2), + babl_component_id (BABL_BLUE_GAMMA_2_2), + babl_component_id (BABL_ALPHA), + NULL); + + babl_pixel_format_new ( + "rgba-float", + "id", BABL_RGBA_FLOAT, + babl_model_id (BABL_RGBA), + babl_type_id (BABL_FLOAT), + babl_component_id (BABL_RED), + babl_component_id (BABL_GREEN), + babl_component_id (BABL_BLUE), + babl_component_id (BABL_ALPHA), + NULL); + + babl_pixel_format_new ( + "rgba-double", + "id", BABL_RGBA_DOUBLE, + babl_model_id (BABL_RGBA), + babl_type_id (BABL_FLOAT), + babl_component_id (BABL_RED), + babl_component_id (BABL_GREEN), + babl_component_id (BABL_BLUE), + babl_component_id (BABL_ALPHA), + NULL); + + babl_pixel_format_new ( + "rgb-float", + "id", BABL_RGB_FLOAT, + babl_model_id (BABL_RGB), + babl_type_id (BABL_FLOAT), + babl_component_id (BABL_RED), + babl_component_id (BABL_GREEN), + babl_component_id (BABL_BLUE), + NULL); +} diff --git a/babl/base/models.c b/babl/base/models.c new file mode 100644 index 0000000..0202888 --- /dev/null +++ b/babl/base/models.c @@ -0,0 +1,21 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl.h" + diff --git a/babl/base/pixel-formats.c b/babl/base/pixel-formats.c new file mode 100644 index 0000000..20bb1b3 --- /dev/null +++ b/babl/base/pixel-formats.c @@ -0,0 +1,49 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl.h" + +void babl_base_pixel_formats (void) +{ + + + babl_pixel_format_new ( + "cmyk-float", + "id", BABL_CMYK_FLOAT, + babl_model_id (BABL_CMYK), + babl_type_id (BABL_FLOAT), + babl_component_id (BABL_CYAN), + babl_component_id (BABL_MAGENTA), + babl_component_id (BABL_YELLOW), + babl_component_id (BABL_KEY), + NULL); + + babl_pixel_format_new ( + "cmyka-float", + "id", BABL_CMYKA_FLOAT, + babl_model_id (BABL_CMYKA), + babl_type_id (BABL_FLOAT), + babl_component_id (BABL_CYAN), + babl_component_id (BABL_MAGENTA), + babl_component_id (BABL_YELLOW), + babl_component_id (BABL_KEY), + babl_component_id (BABL_ALPHA), + NULL); + +} diff --git a/babl/base/rgb-constants.h b/babl/base/rgb-constants.h new file mode 100644 index 0000000..b91d2fc --- /dev/null +++ b/babl/base/rgb-constants.h @@ -0,0 +1,22 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#define RGB_LUMINANCE_RED (0.2126) +#define RGB_LUMINANCE_GREEN (0.7152) +#define RGB_LUMINANCE_BLUE (0.0722) diff --git a/babl/base/type-double.c b/babl/base/type-double.c new file mode 100644 index 0000000..07728b7 --- /dev/null +++ b/babl/base/type-double.c @@ -0,0 +1,49 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl.h" + +static void +convert_double_double (void *src, + void *dst, + int n) +{ + memcpy (dst, src, n/8); +} + +void +babl_base_type_double (void) +{ + babl_type_new ( + "double", + "id", BABL_DOUBLE, + "bits", 64, + NULL); + + babl_conversion_new ( + "babl-base: double to double", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_double_double, + NULL + ); +} diff --git a/babl/base/type-float.c b/babl/base/type-float.c new file mode 100644 index 0000000..ff3d5ce --- /dev/null +++ b/babl/base/type-float.c @@ -0,0 +1,75 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl.h" + +static void +convert_double_float (void *src, + void *dst, + int n) +{ + while (n--) + { + (*(float *) dst) = (*(double *) src); + dst += 4; + src += 8; + } +} + +static void +convert_float_double (void *src, + void *dst, + int n) +{ + while (n--) + { + (*(double *) dst) = (*(float *) src); + dst += 8; + src += 4; + } +} + +void +babl_base_type_float (void) +{ + babl_type_new ( + "float", + "id", BABL_FLOAT, + "bits", 32, + NULL); + + babl_conversion_new ( + "babl-base: float to double", + "source", babl_type_id (BABL_FLOAT), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_float_double, + NULL + ); + + babl_conversion_new ( + "babl-base: double to float", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_FLOAT), + "linear", convert_double_float, + NULL + ); +} diff --git a/babl/base/type-u16.c b/babl/base/type-u16.c new file mode 100644 index 0000000..2b602b0 --- /dev/null +++ b/babl/base/type-u16.c @@ -0,0 +1,84 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl.h" + +static void +convert_double_u16 (void *src, + void *dst, + int n) +{ + while (n--) + { + double dval = *(double *) src; + unsigned short u16val; + + if (dval < 0) + u16val = 0; + else if (dval > 1) + u16val = 65535; + else + u16val = dval*65535.0; + *(unsigned short *) dst = u16val; + dst += 2; + src += 8; + } +} + +static void +convert_u16_double (void *src, + void *dst, + int n) +{ + while (n--) + { + (*(double *) dst) = (*(unsigned short *) src*65535.0); + dst += 8; + src += 2; + } +} + +void +babl_base_type_u16 (void) +{ + babl_type_new ( + "u16", + "id", BABL_U16, + "bits", 16, + NULL); + + babl_conversion_new ( + "babl-base: u16 to double", + "source", babl_type_id (BABL_U16), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u16_double, + NULL + ); + + babl_conversion_new ( + "babl-base: double to u16", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U16), + "linear", convert_double_u16, + NULL + ); +} diff --git a/babl/base/type-u8.c b/babl/base/type-u8.c new file mode 100644 index 0000000..b0d8121 --- /dev/null +++ b/babl/base/type-u8.c @@ -0,0 +1,85 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl.h" + +static void +convert_u8_double (void *src, + void *dst, + int n) +{ + while (n--) + { + (*(double *) dst) = (*(unsigned char *) src/255.0); + dst += 8; + src += 1; + } +} + +static void +convert_double_u8 (void *src, + void *dst, + int n) +{ + while (n--) + { + double dval = *(double *) src; + unsigned char u8val; + + if (dval < 0) + u8val = 0; + else if (dval > 1) + u8val = 255; + else + u8val = dval*255.0; + + *(unsigned char *) dst = u8val; + dst += 1; + src += 8; + } +} + +void +babl_base_type_u8 (void) +{ + babl_type_new ( + "u8", + "id", BABL_U8, + "bits", 8, + NULL); + + babl_conversion_new ( + "babl-base: u8 to double", + "source", babl_type_id (BABL_U8), + "destination", babl_type_id (BABL_DOUBLE), + "linear", convert_u8_double, + NULL + ); + + babl_conversion_new ( + "babl-base: double to u8", + "source", babl_type_id (BABL_DOUBLE), + "destination", babl_type_id (BABL_U8), + "linear", convert_double_u8, + NULL + ); +} diff --git a/babl/base/types.c b/babl/base/types.c new file mode 100644 index 0000000..a9ac707 --- /dev/null +++ b/babl/base/types.c @@ -0,0 +1,24 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl.h" + diff --git a/babl/base/util.h b/babl/base/util.h new file mode 100644 index 0000000..a9d8753 --- /dev/null +++ b/babl/base/util.h @@ -0,0 +1,46 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _UTIL_H +#define _UTIL_H + +#include + +#define BABL_PLANAR_SANITY \ + { \ + assert(src_bands>0); \ + assert(dst_bands>0); \ + assert(src); \ + assert(*src); \ + assert(dst); \ + assert(*dst); \ + assert(n>0); \ + assert(*src_pitch); \ + } + +#define BABL_PLANAR_STEP \ + { \ + int i; \ + for (i=0; i< src_bands; i++) \ + src[i]+=src_pitch[i]; \ + for (i=0; i< dst_bands; i++) \ + dst[i]+=dst_pitch[i]; \ + } + +#endif diff --git a/configure.ac b/configure.ac index 126a9cc..b673e18 100644 --- a/configure.ac +++ b/configure.ac @@ -33,7 +33,7 @@ dnl =========================================================================== AC_OUTPUT(Makefile \ babl.pc \ babl/Makefile \ - babl/babl-base/Makefile \ + babl/base/Makefile \ tests/Makefile \ INSTALL \ README -- 2.30.2